<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="类型（1=碳排因子库，2=组织因子库）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="type">
              <a-input v-model="model.type" placeholder="请输入类型（1=碳排因子库，2=组织因子库）"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="因子名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">
              <a-input v-model="model.name" placeholder="请输入因子名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="规格型号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="model">
              <a-input v-model="model.model" placeholder="请输入规格型号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="行业" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="industry">
              <j-category-select v-model="model.industry" pcode="" placeholder="请选择行业"  />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="因子分类" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productClassification">
              <j-multi-select-tag type="list_multi" v-model="model.productClassification" dictCode="" placeholder="请选择因子分类" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="适用场景" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="scene">
              <a-input v-model="model.scene" placeholder="请输入适用场景"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="说明" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="instruction">
              <a-input v-model="model.instruction" placeholder="请输入说明"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="发布机构" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="releaseOrg">
              <a-input v-model="model.releaseOrg" placeholder="请输入发布机构"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="发布年份" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="releaseYear">
              <a-input v-model="model.releaseYear" placeholder="请输入发布年份"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="来源类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sourceType">
              <a-input v-model="model.sourceType" placeholder="请输入来源类型"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="文献类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="docType">
              <a-input v-model="model.docType" placeholder="请输入文献类型"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="来源文件" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sourceFile">
              <a-input v-model="model.sourceFile" placeholder="请输入来源文件"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="来源归属" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ownership">
              <a-input v-model="model.ownership" placeholder="请输入来源归属"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="来源网址链接" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sourceUrlLink">
              <a-input v-model="model.sourceUrlLink" placeholder="请输入来源网址链接"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="附件地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="attachments">
              <a-input v-model="model.attachments" placeholder="请输入附件地址"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="发布状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="state">
              <a-input v-model="model.state" placeholder="请输入发布状态"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="删除标识" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="delFlag">
              <a-input-number v-model="model.delFlag" placeholder="请输入删除标识" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'CyEmissionFactorForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/emission/factor/cyEmissionFactor/add",
          edit: "/emission/factor/cyEmissionFactor/edit",
          queryById: "/emission/factor/cyEmissionFactor/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }

        })
      },
      handleCategoryChange(value,backObj){
         this.model = Object.assign(this.model, backObj);
      }
    }
  }
</script>
